/**
 * csc(作者)
 * 2018-10-31(开始日期)
 * 2018-10-31(最终更改日期)
 * csc(最后更改者)
 * */
Auth()
//r_type判断用户注册类型
var r_type = globalFun.GetQueryString('v_type');
if(r_type == 1) {
	$('.type_vl').addClass('click_type');
	$('.type_vl').siblings().removeClass('click_type');
	$('#vl_registe').css('display', 'block');
	$('#vt_registe').css('display', 'none');
} else if(r_type == 2) {
	$('.type_tm').addClass('click_type');
	$('.type_tm').siblings().removeClass('click_type');
	$('#vl_registe').css('display', 'none');
	$('#vt_registe').css('display', 'block');
}
//点击切换注册类型
$('.type_vl').on('click', function() {
	window.location.href = 'registe.html?v_type=1'
})
$('.type_tm').on('click', function() {
	//判断用户有没有登录
	if(localStorage.getItem('user_info')) {
		//判断用户是否是个团队
		if(is_team == 1) {
			window.location.href = 'registe.html?v_type=2'
		}else{
			tips('您已经是一个团队了，请不要重复注册')
		}
	} else {
		tips('请先注册成为志愿者，并进行登录')
		setTimeout(function(){
			window.location.href = 'login.html'
		},1000)	
	}
})
//实名志愿者注册******************************************************************
//用户名
var v_username;
var reg0 = /^[a-zA-Z0-9_-]{4,16}$/;
var bol0 = false;
$("#v_username").on('blur', function() {
	if($("#v_username").val() == '') {
		$(this).next().text('用户名不能为空').css('color', 'red').css('display', 'block');
		bol0 = false;
	} else if(reg0.test($("#v_username").val()) == false) {
		$(this).next().text("用户名格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		bol0 = false;
	} else {
		v_username = $("#v_username").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol0 = true;
	};
});
//密码
var v_passward;
var reg1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
var bol1 = false;
$("#v_passward").on('blur', function() {
	if($("#v_passward").val() == '') {
		$(this).next().text('密码不能为空').css('color', 'red').css('display', 'block');
		bol1 = false;
	} else if(reg1.test($("#v_passward").val()) == false) {
		$(this).next().text("密码格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		bol1 = false;
	} else {
		v_passward = $("#v_passward").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol1 = true;
	};
});
//验证密码
var v_passward1;
var reg1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
var bol2 = false;
$("#v_passward1").on('blur', function() {
	if($("#v_passward1").val() == '') {
		$(this).next().text('密码不能为空').css('color', 'red').css('display', 'block');
		bol2 = false;
	} else if(reg1.test($("#v_passward1").val()) == false) {
		$(this).next().text("密码格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		bol2 = false;
	} else if($("#v_passward1").val() != $("#v_passward").val()) {
		$(this).next().text("两次密码输入不一致，请重新输入").css('color', 'red').css('display', 'block');
		bol2 = false;
	} else {
		v_passward1 = $("#v_passward1").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol2 = true;
	};
});
//邮箱
var v_mail;
var reg2 = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
var bol3 = false;
$("#v_mail").on('blur', function() {
	if($("#v_mail").val() == '') {
		$(this).next().text('邮箱不能为空').css('color', 'red').css('display', 'block');
		bol3 = false;
	} else if(reg2.test($("#v_mail").val()) == false) {
		$(this).next().text("电子邮箱格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		bol3 = false;
	} else {
		v_mail = $("#v_mail").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol3 = true;
	};
});
//真实姓名
var v_name;
var reg3 = /^[\u4E00-\u9FA5\uf900-\ufa2d]{2,4}$/
var bol4 = false;
$("#v_name").on('blur', function() {
	if($("#v_name").val() == '') {
		$(this).next().text('姓名不能为空').css('color', 'red').css('display', 'block');
		bol4 = false;
	} else if(reg3.test($("#v_name").val()) == false) {
		$(this).next().text("姓名格式不正确，请与证件上保持一致").css('color', 'red').css('display', 'block');
		bol4 = false;
	} else {
		v_name = $("#v_name").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol4 = true;
	};
	console.log(v_name)
});
//身份证号
var card_num;
var reg4 = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
var bol5 = false;
$("#card_num").on('blur', function() {
	if($("#card_num").val() == '') {
		$(this).next().text('身份证号不能为空').css('color', 'red').css('display', 'block');
		bol5 = false;
	} else if(reg4.test($("#card_num").val()) == false) {
		$(this).next().text("身份证号格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		bol5 = false;
	} else {
		card_num = $("#card_num").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol5 = true;
	};
});
//性别
var sex;
//出生日期
var birth_time;
var bol6 = false;
$("#birth_time").on('blur', function() {
	if($("#birth_time").val() == '') {
		$(this).next().text('出生日期不能为空').css('color', 'red').css('display', 'block');
		bol6 = false;
	} else {
		birth_time = $("#birth_time").val();
		bol6 = true;
	};
});
//政治面貌
var politics_type;

//民族
var nation;
var bol7 = false;
$("#nation").on('blur', function() {
	if($("#nation").val() == '') {
		$(this).next().text('民族不能为空').css('color', 'red').css('display', 'block');
		bol7 = false;
	} else if(reg3.test($("#nation").val()) == false) {
		$(this).next().text("请与证件上保持一致").css('color', 'red').css('display', 'block');
		bol7 = false;
	} else {
		nation = $("#nation").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol7 = true;
	};
});
//籍贯
var nation_place;
var bol8 = false;
$("#nation_place").on('blur', function() {
	if($("#nation_place").val() == '') {
		$(this).next().text('籍贯不能为空').css('color', 'red').css('display', 'block');
		bol8 = false;
	} else {
		nation_place = $("#nation_place").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol8 = true;
	};
	console.log(v_name)
});
//手机号码
var v_phone;
var reg5 = /^1(3|4|5|7|8|9)\d{9}$/;
var bol9 = false;
$("#v_phone").on('blur', function() {
	if($("#v_phone").val() == '') {
		$(this).next().text('手机号不能为空').css('color', 'red').css('display', 'block');
		bol9 = false;
	} else if(reg5.test($("#v_phone").val()) == false) {
		$(this).next().text("手机号格式不正确").css('color', 'red').css('display', 'block');
		bol9 = false;
	} else {
		v_phone = $("#v_phone").val();
		console.log(v_phone)
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		bol9 = true;
	};
});
//详细地址
var v_address;
var bol10 = false;
$("#v_address").on('blur', function() {
	console.log($("#v_address").val())
	if($("#v_address").val() == '') {
		$(this).next().text('详细地址不能为空').css('color', 'red').css('display', 'block');
		bol10 = false;
	} else {
		v_address = $("#v_address").val();
		console.log(v_address)
		bol10 = true;
	};
});
//最高学历
var school_type;
//从业状况
var job_type;
//服务区域
var address_type;
//服务类型(最多三项)
var v_serverType;
$("#v_server_type input:checkbox").click(function() {
	console.log(3333)
	var radio_len = $("#v_server_type input:checked").length;
	if(radio_len > 3) {
		$("#v_server_type").next().text('最多选择3个').css('color', 'red').css('display', 'block');
		return false;
	} else {
		$("#v_server_type").next().text('');
	}
})
//服务领域或行业(可全选)
var server_job;
//志愿者注册**************************************************
$('#volunteer_people_registe').on('click', function() {
	var volunteerObj = {};
	if(bol0 && bol1 && bol2 && bol3 && bol4 && bol5 && bol6 && bol7 && bol8 && bol9 && bol10) {
		volunteerObj.username = v_username;
		volunteerObj.password = v_passward1;
		volunteerObj.email = v_mail;
		volunteerObj.realName = v_name;
		volunteerObj.idCard = card_num;
		volunteerObj.birthday = birth_time;
		volunteerObj.nation = nation;
		volunteerObj.nativePlace = nation_place;
		volunteerObj.phone = v_phone;
		volunteerObj.address = addressName;
		volunteerObj.longitude = longitude;
		volunteerObj.latitude = latitude;
		//性别		
		var sex = $('input:radio[name="sex"]:checked').val();
		if(sex == '' || sex == undefined) {
			tips('请选择性别');
			return false
		} else {
			volunteerObj.sex = sex;
		};
		//身份
		var politics_type = $("#politics_type  option:selected").text();
		if(politics_type == '请选择' || politics_type == undefined) {
			tips('请选择最高学历');
			return false;

		} else {
			volunteerObj.political = politics_type;
		};
		//学历
		var school_type = $("#school_type  option:selected").text();
		if(school_type == '请选择' || school_type == undefined) {
			tips('请选择最高学历');
			return false;
		} else {
			volunteerObj.education = school_type;
		};
		//工作状况
		var job_type = $("#job_type  option:selected").text();
		if(job_type == '请选择' || job_type == undefined) {
			tips('请选择就业状况');
			return false;
		} else {
			volunteerObj.jobStatus = job_type;
		};
		//服务区域
		var address_type = $("#address_type  option:selected").val();
		if(address_type == '请选择' || address_type == undefined) {
			tips('请选择服务区域');
			return false;
		} else {
			volunteerObj.areaId = address_type;
		};
		//服务类型
		var fk = [];
		var ffkk = '';
		var sl = $("#v_server_type input:checked").length;
		if(sl == 0) {
			tips('请选择服务领域或行业')
		} else {
			for(var i = 0; i < sl; i++) {
				fk.push($("#v_server_type input:checked").eq(i).val())
			}
			if(fk.length == 1) {
				ffkk = fk.join()
			} else if(fk.length > 1) {
				ffkk = fk.join(',')
			}
			volunteerObj.serviceType = ffkk
		}
		//服务领域或行业
		var hy = [];
		var hhyy = '';
		var gt = $("#server_job input:checked").length;
		if(gt == 0) {
			tips('请选择服务领域或行业')
		} else {
			for(var i = 0; i < gt; i++) {
				hy.push($("#server_job input:checked").eq(i).val())
			}
			if(hy.length == 1) {
				hhyy = hy.join()
			} else if(hy.length > 1) {
				hhyy = hy.join(',')
			}
			volunteerObj.serviceScope = hhyy
		}
		//用户图像
		if(vlImg == '' || vlImg == undefined) {
			tips('请上传用户图像')
			return false;
		} else {
			volunteerObj.imgUrl = vlImg;
		}
		console.log(volunteerObj)
		//调取注册借口		
		$.ajax({
			type: "post",
			url: apicom + "/login/register",
			async: false,
			dataType: "json",
			data: volunteerObj,
			success: function(res) {
				if(res.code==200){
					tips('注册成功，请前往登录')
					setTimeout(function(){
						window.location.href = 'login.html'
					},1000)
				}else{
					tips(res.message)
				}
			},
			error: function(err) {

			}
		});
	} else {
		tips('请查看注册信息是否填写完整')
	}
})
//********************************************************
//团队注册
var username;
var t_bol0 = false;
$("#username").on('blur', function() {
	if($("#username").val() == '') {
		$(this).next().text('用户名不能为空').css('color', 'red').css('display', 'block');
		t_bol0 = false;
	} else if(reg0.test($("#username").val()) == false) {
		$(this).next().text("用户名格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		t_bol0 = false;
	} else {
		username = $("#username").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol0 = true;
	};
});
//密码
var passward;
var t_bol1 = false;
$("#passward").on('blur', function() {
	if($("#passward").val() == '') {
		$(this).next().text('密码不能为空').css('color', 'red').css('display', 'block');
		t_bol1 = false;
	} else if(reg1.test($("#passward").val()) == false) {
		$(this).next().text("密码格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		t_bol1 = false;
	} else {
		passward = $("#passward").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol1 = true;
	};
});
//验证密码
var passward1;
var t_bol2 = false;
$("#passward1").on('blur', function() {
	if($("#passward1").val() == '') {
		$(this).next().text('密码不能为空').css('color', 'red').css('display', 'block');
		t_bol2 = false;
	} else if(reg1.test($("#passward1").val()) == false) {
		$(this).next().text("密码格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		t_bol2 = false;
	} else if($("#passward1").val() != $("#passward").val()) {
		$(this).next().text("两次密码输入不一致，请重新输入").css('color', 'red').css('display', 'block');
		t_bol2 = false;
	} else {
		passward1 = $("#passward1").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol2 = true;
	};
});
//邮箱
var mail;
var t_bol3 = false;
$("#mail").on('blur', function() {
	if($("#mail").val() == '') {
		$(this).next().text('邮箱不能为空').css('color', 'red').css('display', 'block');
		t_bol3 = false;
	} else if(reg2.test($("#mail").val()) == false) {
		$(this).next().text("电子邮箱格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		t_bol3 = false;
	} else {
		mail = $("#mail").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol3 = true;
	};
});
//志愿团体名称
var team_name;
var t_bol4 = false;
$("#team_name").on('blur', function() {
	if($("#team_name").val() == '') {
		$(this).next().text('志愿团体不能为空').css('color', 'red').css('display', 'block');
		t_bol4 = false;
	} else if(reg3.test($("#team_name").val()) == false) {
		$(this).next().text("志愿团体格式不正确").css('color', 'red').css('display', 'block');
		t_bol4 = false;
	} else {
		team_name = $("#team_name").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol4 = true;
	};
	console.log(team_name)
});
//志愿团体描述;
var description;
var t_bol13 = false;
$("#description").on('blur', function() {
	if($("#description").val() == '') {
		$(this).next().text('志愿团体不能为空').css('color', 'red').css('display', 'block');
		t_bol13 = false;
	} else {
		description = $("#description").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol13 = true;
	};
	console.log(team_name)
});
//主管单位名称
var competent_name;
var t_bol5 = false;
$("#competent_name").on('blur', function() {
	if($("#competent_name").val() == '') {
		$(this).next().text('主管单位不能为空').css('color', 'red').css('display', 'block');
		t_bol5 = false;
	} else if(reg3.test($("#competent_name").val()) == false) {
		$(this).next().text("主管单位格式不正确").css('color', 'red').css('display', 'block');
		t_bol5 = false;
	} else {
		competent_name = $("#competent_name").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol5 = true;
	};
	console.log(competent_name)
});
//详细地址
var competent_address;
var t_bol6 = false;
$("#competent_address").on('blur', function() {
	console.log($("#competent_address").val())
	if($("#competent_address").val() == '') {
		$(this).next().text('详细地址不能为空').css('color', 'red').css('display', 'block');
		t_bol6 = false;
	} else {
		competent_address = $("#competent_address").val();
		console.log(competent_address)
		t_bol6 = true;
	};
});
//招募人数
var competent_num;
var t_bol7 = false;
$("#competent_num").on('blur', function() {
	console.log($("#competent_num").val())
	if($("#competent_num").val() == '') {
		$(this).next().text('招募人数不能为空').css('color', 'red').css('display', 'block');
		t_bol7 = false;
	} else {
		competent_num = $("#competent_num").val();
		console.log(competent_num)
		t_bol7 = true;
	};
});
//服务类型(最多三项)
var serverType;
$("#server_type input:checkbox").click(function() {
	console.log(3333)
	var radio_len = $("#server_type input:checked").length;
	if(radio_len > 3) {
		$("#server_type").next().text('最多选择3个').css('color', 'red').css('display', 'block');
		return false;
	} else {
		$("#server_type").next().text('');
	}
})
//联系人姓名
var contacts_name;
var t_bol8 = false;
$("#contacts_name").on('blur', function() {
	if($("#contacts_name").val() == '') {
		$(this).next().text('联系人不能为空').css('color', 'red').css('display', 'block');
		t_bol8 = false;
	} else if(reg3.test($("#contacts_name").val()) == false) {
		$(this).next().text("联系人格式不正确").css('color', 'red').css('display', 'block');
		t_bol8 = false;
	} else {
		contacts_name = $("#contacts_name").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol8 = true;
	};
	console.log(contacts_name)
});

//联系人手机号码
var contacts_phone;
var t_bol9 = false;
$("#contacts_phone").on('blur', function() {
	if($("#contacts_phone").val() == '') {
		$(this).next().text('手机号不能为空').css('color', 'red').css('display', 'block');
		t_bol9 = false;
	} else if(reg5.test($("#contacts_phone").val()) == false) {
		$(this).next().text("手机号格式不正确").css('color', 'red').css('display', 'block');
		t_bol9 = false;
	} else {
		contacts_phone = $("#contacts_phone").val();
		console.log(contacts_phone)
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol9 = true;
	};
});
//负责人姓名
var person_name;
var t_bol10 = false;
$("#person_name").on('blur', function() {
	if($("#person_name").val() == '') {
		$(this).next().text('负责人不能为空').css('color', 'red').css('display', 'block');
		t_bol10 = false;
	} else if(reg3.test($("#person_name").val()) == false) {
		$(this).next().text("负责人姓名格式不正确").css('color', 'red').css('display', 'block');
		t_bol10 = false;
	} else {
		person_name = $("#person_name").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol10 = true;
	};
	console.log(person_name)
});
//负责人身份证
var person_IDcard;
var t_bol11 = false;
$("#person_IDcard").on('blur', function() {
	if($("#person_IDcard").val() == '') {
		$(this).next().text('身份证号不能为空').css('color', 'red').css('display', 'block');
		t_bol11 = false;
	} else if(reg4.test($("#person_IDcard").val()) == false) {
		$(this).next().text("身份证号格式不正确，请重新输入").css('color', 'red').css('display', 'block');
		t_bol11 = false;
	} else {
		person_IDcard = $("#person_IDcard").val();
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol11 = true;
	};
});
//负责人电话
var person_phone;
var t_bol12 = false;
$("#person_phone").on('blur', function() {
	if($("#person_phone").val() == '') {
		$(this).next().text('负责人电话不能为空').css('color', 'red').css('display', 'block');
		t_bol12 = false;
	} else if(reg5.test($("#person_phone").val()) == false) {
		$(this).next().text("手机号格式不正确").css('color', 'red').css('display', 'block');
		t_bol12 = false;
	} else {
		person_phone = $("#person_phone	").val();
		console.log(contacts_phone)
		$(this).next().text('输入正确').css('color', 'limegreen').css('display', 'block');
		t_bol12 = true;
	};
});
//志愿者团队注册**************************************************
$('#volunteer_team_registe').on('click', function() {
			var volunteerObj = {};
			if(t_bol0 && t_bol1 && t_bol2 && t_bol3 && t_bol4 && t_bol5 && t_bol6 && t_bol7 && t_bol8 && t_bol9 && t_bol10 && t_bol11 && t_bol12&& t_bol13) {
				volunteerObj.uuid=uuid;
				volunteerObj.memberId = id;
				volunteerObj.loginType = is_team;				
				volunteerObj.username = username;
				volunteerObj.password = passward1;
				volunteerObj.mail = mail;
				volunteerObj.name = team_name;				
				volunteerObj.description = description;
				volunteerObj.supervisorName = competent_name;
				volunteerObj.address = t_addressName;
				volunteerObj.longitude = t_longitude;
				volunteerObj.latitude = t_latitude;
				volunteerObj.teamNum = competent_num;			
				volunteerObj.linkName = contacts_name;
				volunteerObj.telPhone = contacts_phone;
//				volunteerObj.linkQq = v_phone;				
				volunteerObj.personName = person_name;
				volunteerObj.person_idcard = person_IDcard;
				volunteerObj.personPhone = person_phone;
				
				//单位类型
				var competent_type = $("#competent_type  option:selected").val();
				if(competent_type == '请选择' || competent_type == undefined) {
					tips('请选择主管单位类型');
					return false;
				} else {
					volunteerObj.supervisorType = competent_type;
				};
				//服务区域
				var address_type = $("#t_address_type  option:selected").val();
				if(address_type == '请选择' || address_type == undefined) {
					tips('请选择服务区域');
					return false;
				} else {
					volunteerObj.areaId = address_type;
				};
				//联系人QQ
				volunteerObj.linkQq = $('#contacts_qq').val();
				//服务类型
				var fk = [];
				var ffkk = '';
				var sl = $("#server_type input:checked").length;
				if(sl == 0) {
					tips('请选择服务类别')
				} else {
					for(var i = 0; i < sl; i++) {
						fk.push($("#server_type input:checked").eq(i).val())
					}
					if(fk.length == 1) {
						ffkk = fk.join()
					} else if(fk.length > 1) {
						ffkk = fk.join(',')
					}
					volunteerObj.serviceType = ffkk
				}
				//团队图像
				if(vtImg == '' || vtImg == undefined) {
					tips('请上传用户图像')
					return false;
				} else {
					volunteerObj.imgUrl = vtImg;
				}
				console.log(volunteerObj)
				//调取注册借口		
				$.ajax({
					type: "post",
					url: apicom + "/team/register",
					async: false,
					dataType: "json",
					data: volunteerObj,
					success: function(res) {
						if(res.code==200){
							tips('注册成功，请前往登录')
							setTimeout(function(){
								window.location.href = 'login.html'
							},1000)
						}else{
							tips(res.message)
						}
					},
					error: function(err) {
						
					}
				});
			} else {
				tips('请查看注册信息是否填写完整')
			}
})
//获取服务区域
$.ajax({
	type: "post",
	url: apicom + "/area/getAreaInfo",
	async: true,
	success: function(res) {
		var data = res.data;
		var ss = '';
		for(var i = 0; i < data.length; i++) {
			ss += '<option value="' + data[i].id + '">' + data[i].name + '</option>'
		}
		$("#address_type").html(ss);
		$("#t_address_type").html(ss);
	},
	error: function(err) {

	}
});